<template>
    <view class="app">
         <uni-list>
        	<uni-list-item title="姓名" :custom="true" :show-arrow="false">
			<div class="inputTip_box">
			  <input type="text" placeholder="请输入名称"  v-model="form.dhc_shopname"><!-- @blur="validateName"-->
			  <span class="inputTip">{{inputTip}}</span>
			</div>
		</uni-list-item>
         <uni-list-item title="联系方式" :custom="true" :show-arrow="false">
          <div class="inputTip_box">
            <input type="text" placeholder="请输入手机号码" :maxlength="11" v-model="form.dhc_telephone"><!-- @blur="validateName"-->
            <span class="inputTip">{{inputTip}}</span>
          </div>
        </uni-list-item>

        </uni-list>
        <view class="submit_btn" @click="submit">立即邀请</view>
        	<!--mpvue-city-picker :pickerValueDefault="defaultArea" themeColor="#FFD11A"
        ref="mpvueCityPicker" @onConfirm="onConfirm"></mpvue-city-picker-->
    </view>
</template>

<script>
import { addInviteShop } from '@/api/getGuest'
import uniList from '@/components/uni-list/uni-list'
import uniListItem from '@/components/uni-list-item/uni-list-item'
// import mpvueCityPicker from '@/components/mpvue-citypicker/mpvueCityPicker'
export default {
	name: 'inviteShop',
	components: {
		uniList,
		uniListItem
		// mpvueCityPicker
	},
	data() {
		return {
			form: {
				dhc_shopname: ' ',
				dhc_telephone: ' '
			},
			inputTip: '',
			option: {}
		}
	},
	onLoad(option) {
		this.option = option
	},
	methods: {
		/* selArea() {
			this.$refs.mpvueCityPicker.show()
		},*/
		onConfirm() {
			this.form = {
				dhc_telephone: this.form.dhc_telephone,
				dhc_shopname: this.form.dhc_shopname
			}
		},
		/* validateName() {
			const nameReg = /^[a-zA-Z\d\u4E00-\u9FA5]{1,12}$/g
			if (nameReg.test(this.form.dhc_shopname) || !this.form.dhc_shopname) {
				this.inputTip = ''
			} else if (this.form.dhc_shopname) {
				this.inputTip = '格式错误'
			}
		},*/
		submit() {
			let flag = true
			Object.keys(this.form).forEach(item => {
				if (!this.form[item]) {
					uni.showToast({
						title: '请输入完整信息',
						icon: 'none'
					})
					flag = false
				}
			})
			if (this.inputTip) {
				flag = false
			}
			if (flag) {
				addInviteShop(this.form).then(() => {
					uni.showToast({
						title: '添加成功',
						icon: 'success'
					})
					setTimeout(() => {
						let pages = getCurrentPages()// 获取页面栈
						let prevPage = pages[pages.length - 2]// 上一个页面
			   			if (prevPage) {
							// prevPage.$vm.form.district_id = this.form.district
							// prevPage.$vm.selIndex = null
							// prevPage.$vm.community_id = ''
							uni.navigateBack()
						}
						// const params = {
						// 	...this.option,
						// 	district_id: this.form.district
						// }
						// uni.navigateTo({
						// 	url: `/pages/constructionSite/communityList${this.commonJS.queryData(params)}`
						// })
					}, 500)
				})
			}
		}
	}
}
</script>

<style scoped>
 .phStyle {
      color: gray;
    }
      .submit_btn {
	height:90px;
	width: 100%;
	position: fixed;
	display: flex;
	align-items: center;
	justify-content: center;
	line-height: 45px;
	bottom: 0;
	background:rgba(255,209,26,1);
	font-size:24px;
	color:rgba(58,27,4,1);
    }
</style>
